<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>scrollTop&Left</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }

        .box{
            position: absolute;
            top: 50px;
            left: 50px;
            width: 150px;
            height: 150px;
            background-color: #f00;
            overflow: scroll;
        }

        .inner {
            width: 400px;
            height: 400px;
            background-color: #ff9000;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="inner"></div>
    </div>

    <script type="text/javascript">
        var box = document.querySelector(".box");

        // elem.scrollTop/Left 返回元素被卷入的上左边距
        // scrollTop/Left 三大家族中唯一  可读写的值，读取的值可以不是整数
        box.onclick = function (){
            this.scrollTop = 50;
            this.scrollLeft = 50;
            console.log("box.scroll", { top: box.scrollTop, left: box.scrollLeft});
        }
        
        // 监听滚动事件  element.onscroll
        box.onscroll = function (){
            console.log("box.scroll", { top: box.scrollTop, left: box.scrollLeft});
        }
    </script>
</body>
</html>